//
//  RewardVideoDemoVC.m
//  JAGatherAdDemo
//
//  Created by Yc on 2022/4/24.
//

#import "RewardVideoDemoVC.h"
#import <JAGatherAdSDK/JAGatherAdSDK.h>

@interface RewardVideoDemoVC ()<JAGAdRewardVideoDelegate>

@property (nonatomic, strong) JAGAdRewardVideo *rewardVideo;

@end

@implementation RewardVideoDemoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.placementList = [[NSMutableArray alloc] initWithArray:[self readPlacementDataOfType:DataType_rewardVideo]];
    [self setupPlacement:rewardID];
    [self creatRewardVideo];
}

- (void)creatRewardVideo {
    [self deallocAd];
    self.rewardVideo = [[JAGAdRewardVideo alloc] initWithPlacementID:[self getPlacement]];
    self.rewardVideo.viewController = self;
    self.rewardVideo.delegate = self;
}

- (void)deallocAd {
    self.rewardVideo = nil;
    self.rewardVideo.delegate = nil;
}

- (void)loadAdAction {
    [super loadAdAction];
    NSLog(@"%s", __FUNCTION__);
    TOAST(@"开始加载广告数据");
    [self.rewardVideo loadAd];
    [self writePlacementDataOfType:DataType_rewardVideo];
}

- (void)showAdAction {
    [super showAdAction];
    NSLog(@"%s", __FUNCTION__);
    if (self.rewardVideo && [self.rewardVideo isValid]) {
        [self.rewardVideo showAd];
    }else{
        TOAST(@"请先加载广告数据");
    }
}

- (void)loadAndShowAdAction {
    [super loadAndShowAdAction];
    NSLog(@"%s", __FUNCTION__);
    TOAST(@"开始加载广告数据");
    [self.rewardVideo loadAndShowAd];
    [self writePlacementDataOfType:DataType_rewardVideo];
}

- (void)reselectPlacementAction {
    [self creatRewardVideo];
}

- (void)dealloc {
    NSLog(@"%s", __FUNCTION__);
}


#pragma mark - JAGAdRewardVideoDelegate

/// 激励视屏广告数据请求成功
- (void)JAGatherRewardVideoAdSuccessLoad:(JAGAdRewardVideo *)rewardVideo {
    NSLog(@"%s", __FUNCTION__);
}

/// 激励视屏广告视频缓存完成 (为了更好的用户体验，建议此时显示视频广告)
- (void)JAGatherRewardVideoAdCacheFinish:(JAGAdRewardVideo *)rewardVideo {
    NSLog(@"%s", __FUNCTION__);
    TOAST(@"数据加载完成");
}

/// 激励视屏广告数据请求失败
- (void)JAGatherRewardVideoAdFailLoad:(JAGAdRewardVideo *)rewardVideo error:(NSError *)error {
    NSLog(@"%s %@", __FUNCTION__,error);
    NSString *msg = [NSString stringWithFormat:@"%@",error];
    TOAST(msg);
}

/// 激励视屏广告曝光回调
- (void)JAGatherRewardVideoAdExposured:(JAGAdRewardVideo *)rewardVideo {
    NSLog(@"%s", __FUNCTION__);
}

/// 激励视屏广告点击回调
- (void)JAGatherRewardVideoAdClicked:(JAGAdRewardVideo *)rewardVideo {
    NSLog(@"%s", __FUNCTION__);
}

/// 激励视屏广告页关闭
- (void)JAGatherRewardVideoAdClosed:(JAGAdRewardVideo *)rewardVideo {
    NSLog(@"%s", __FUNCTION__);
}

/// 激励视屏视频播放完成
- (void)JAGatherRewardVideoAdPlayFinish:(JAGAdRewardVideo *)rewardVideo {
    NSLog(@"%s", __FUNCTION__);
}

/// 激励视屏到达激励时间
- (void)JAGatherAdRewardVideoAdDidRewardEffective:(JAGAdRewardVideo *)rewardVideo {
    NSLog(@"%s", __FUNCTION__);
}

@end
